<template>
  <div id="back-div" class="login-back-ground">
    <FormWin ref="loginWin" height="330px" :sure-function="loginSubmit">
      <div class="login-input-item">
        <InputComponent input-name="userName" ref="userName" input-lable="用户名" input-type="text"/>
      </div>
      <div class="login-input-item">
        <InputComponent input-name="userNo" ref="userNo" input-lable="用户号" input-type="text"/>
      </div>
      <div class="login-input-item">
        <InputComponent input-name="userPassword" ref="userPassword" input-lable="密码" input-type="password"/>
      </div>
      <div class="login-input-item-hidden">
        <InputComponent input-name="operType" ref="operType" input-lable="密码" input-type="disable" default-value="0"/>
      </div>
      <span class="errorMsg-span">{{errorMsg}}</span>
    </FormWin>
  </div>
</template>

<script>
import FormWin from "@/components/win/FormWin";
import InputComponent from "@/components/input/InputComponent";
import {postRequest, setSessionId} from "@/axio2";

export default {
  name: "Login",
  components: {InputComponent, FormWin},
  data(){
    return{
      errorMsg:""
    }
  },
  methods:{
    loginSubmit(component){
      let param = this.$refs["loginWin"].getValues();
      console.log(param);
      postRequest(
          "userLogin/baseLogin.do",
          param,
          this.loginSuccess,
          this.loginError,
          this
      );
    },
    loginSuccess(resp,component){
      let loginResp = JSON.parse(resp.data.errorMsg);
      setSessionId(loginResp.sessionId);
      this.$parent.$emit("loginSuccessEvent")
    },
    loginError(resp,component){
      this.errorMsg = resp.data.errorMsg;
      this.$refs["loginWin"].showWin();
    }
  },
  mounted() {
    let contentHeight = window.innerHeight;
    document.getElementById("back-div").style.setProperty("height",contentHeight+"px");
    this.$refs["loginWin"].showWin();
  }
}
</script>
<style scoped>
.login-back-ground{
  background:url('../assets/loginback.jpeg') no-repeat;
  width: 100%;
}
.login-input-item{
  padding-top: 10px;
  padding-bottom: 5px;
}
.errorMsg-span{
  font-size: small;
  color: red;
}
.login-input-item-hidden{
  display: none;
}
</style>